<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0, minimum-scale=1.0, user-scalable=0, initial-scale=1.0, width=device-width"/>
    <meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
    <title>申请成为项目经理</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../../css/main.css" />
    <link rel="stylesheet" type="text/css" href="../../css/project.css" />
</head>
<body>
  <div id="header">
      <div id="back"></div>
      <h3>申请成为项目经理</h3>
  </div>
  <div id="all">
    <div class="apply_ing">
      <div>您已经提交了申请，正在审核中……</div>
    </div>
    <div class="applyManage" style="display:none">
      <div class="item" style="text-align:center;padding:10px;"><img src="" class="userHeaderImageUrl"/></div>
      <div class="item"><span>昵称：</span><span class="nickname"></span></div>
      <div class="item"><span>身份证号：</span><span><input type="text" class="idcard"/></span></div>
      <div class="item"><span>真实姓名：</span><span><input type="text" class="username"/></span></div>
      <div class="item"><span>性别</span><span class="sex"><label>男</label><input type="radio" name="sex" checked value="男"/><label>女</label><input type="radio" name="sex" value="女"/></span></div>
      <div class="item"><span>生日：</span><span class="birthday" style="color:#37acfe">请选择生日</span></div>
      <div class="item"><span>电话：</span><span><input type="text" class="phone"/></span></div>
      <div class="item"><span>邮箱：</span><span><input type="text" class="email"/></span></div>
      <div class="item"><span>地址：</span><span><input type="text" class="address"/></span></div>
      <div class="item"><span>求职状态：</span><span><input type="text" class="getJob"/></span></div>
      <div class="item"><span>个人简介：</span><span><input type="text" class="myIntro"/></span></div>
    </div>
    <div class="myProject apply">
      <div class="job_contact">
        <button class="job_btn info enjoy">申请成为项目经理</button>
      </div>
    </div>
  </div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/jquery.js"></script>
<script type="text/javascript" src="../../script/main.js"></script>
<script type="text/javascript">
var data="";
//apiready执行函数
apiready=function(){
  var aid=$api.getStorage('aid');
  var flag=$api.getStorage('flag');
  var token=$api.getStorage('jwt');
  var projectId="";
  var birthday="";
  if(flag==0||flag==5||flag==6){
      $(".applyManage").show();
      //回显个人信息
      api.ajax({
        url: 'http://47.104.170.122/v1/portal/auth/app/loginInfo?token='+token,
        method: 'GET',
        headers: {
          "Access-Control-Allow-Origin": "*",
          "Access-Control-Allow-Headers": "Authorization",
          "Content-Type" : 'application/json; charset=utf-8'
        }
      }, function(ret, err) {
          if (ret.code==0) {
              var headImagesUrl=ret.data.userHeaderImageUrl;
              var nickname=ret.data.nickname;
              $(".userHeaderImageUrl").attr("src",headImagesUrl);
              $(".nickname").html(nickname);
          } else {
            toast("加载个人资料失败！","bottom");
          }
      });
    }else if(flag==1||flag==2){
      $(".apply_ing").show();
    }else if(flag==3||flag==4){
      $(".enjoy").hide();
      $(".job_contact").append('<button class="job_btn info join">加入该企业</button>')
      //获取全部企业列表
      var url='/student/projects?pageNum=1&pageSize=100&majorId=1';
      var functionRet=function(ret){
        var json=ret.data;
        $.each(json, function(commentIndex, comment){
            if(json[commentIndex].enterpriseName!=""){
              var isStuManager=json[commentIndex].isStuManager;
              if(isStuManager==null){
                isStuManager='可申请'
              }
              else if(isStuManager==0){
                isStuManager='待审核'
              }
              else if(isStuManager==1){
                isStuManager='未通过'
              }
              else if(isStuManager==2){
                isStuManager='已通过'
              }
              var templates='<div class="list"><div class="company_name" projectId="'+json[commentIndex].id+'">'+json[commentIndex].enterpriseName+'<span class="check">'+isStuManager+'</span></div></div>';
              $(".myProject").append(templates);
            }
       });
      }
      var functionErr=function(err){
          showProgress();
      }
      //加载企业列表
      getNewU(url,functionRet,functionErr);
    }

    //选择公司
    $(".apply").on("touchstart",".list",function(){
      addActive($(this),$(this).siblings());
      projectId=$(this).find(".company_name").attr("projectId");
    })
    //选择生日
    $(".birthday").click(function(){
      api.openPicker({
        type: 'date',
        title: '选择生日'
    }, function(ret, err) {
        if (ret) {
          if(ret.month.toString().length==1){
            birthday=ret.year+"-0"+ret.month;
          }else{
            birthday=ret.year+"-"+ret.month;
          }
          if(ret.day.toString().length==1){
            birthday=birthday+"-0"+ret.day;
          }else{
            birthday=birthday+"-"+ret.day;
          }
            $(".birthday").html(birthday);
        } else {

        }
    });
    })
    //申请
    $(".enjoy").click(function(){
      if($(".apply_ing").css("display")=='show'){
        toast("您已经提交了申请，请勿重复提交","middle");
      }else if(flag==0||flag==5||flag==6){
        var userHeaderImageUrl=$(".userHeaderImageUrl").attr("src");
        if(userHeaderImageUrl=="#"){

        }else{
          userHeaderImageUrl=userHeaderImageUrl.split("download/")[1]
        }
        var nickname=$(".nickname").html();
        var idcard=$(".idcard").val();
        var username=$(".username").val();
        var phone=$(".phone").val();
        var email=$(".email").val();
        var address=$(".address").val();
        var getJob=$(".getJob").val();
        var myIntro=$(".myIntro").val();
        var sex=$(".sex input[type='radio']:checked").val();
        var data={
            "img":userHeaderImageUrl,
            "nick":nickname,
            "idcard":idcard,
            "rname":username,
            "sex":sex,
            "birthday":birthday,
            "phone":phone,
            "email":email,
            "address":address,
            "jodstatus":getJob,
            "personal":myIntro
        };
        console.log(userHeaderImageUrl+","+nickname+","+idcard+","+username+","+phone+","+email+","+address+","+getJob+","+myIntro+","+sex+","+birthday)
        if(userHeaderImageUrl!=""&&nickname!=""&&idcard!=""&&username!=""&&phone!=""&&email!=""&&address!=""&&getJob!=""&&myIntro!=""&&sex!=""&&birthday!=""){
          api.ajax({
            url: 'http://47.104.170.122/v1/portal/basic/stuManager/add?token='+token,
            method: 'POST',
            headers: {
              "Access-Control-Allow-Origin": "*",
              "Access-Control-Allow-Headers": "Authorization",
              "Content-Type" : 'application/json; charset=utf-8'
            },
            data:{body:data}
          }, function(ret, err) {
            console.log(ret.code)
            console.log(ret.msg)
              if (ret.code==0) {
                toast("申请成功！","middle")
                $api.setStorage('flag', ret.data.flag);
                closeWin();
              } else {
                toast("申请失败！","middle");
              }
          });
        }else{
          toast("请完善信息","middle");
        }
      }
    })
    //项目经理加入企业
    $("body").on("click",".join",function(){
      var url='http://47.104.170.122/v1/portal/schoolEnterprise/student/applyStuManager?projectId='+projectId+'&token='+token;
      console.log(url)
      var data={};
      api.ajax({
        url: url,
        method: 'POST',
        headers: {
          "Access-Control-Allow-Origin": "*",
          "Access-Control-Allow-Headers": "Authorization",
          "Content-Type" : 'application/json; charset=utf-8'
        },
        data:{body:data}
      }, function(ret, err) {
          if(ret.code==0){
            toast("申请成功","middle");
            setTimeout("closeWin()",2000);
          }else{
            toast("申请失败","middle")
          }
      });
    })
}//apiready=function(){ 函数的反括号
  //jquery
  $(function(){
    back();
  })
</script>

</html>
